

var app = getApp()
var util = require('../../utils/util.js')
Page({

  /**
   * 页面的初始数据
   */
  data: {
    order:null,
    id:null,
    groupid:null,
    pageInfo:{}
  },
  // 进入商城首页
  gomall(){
    wx.switchTab({
      url: "/pages/index/index"
    });
  },
  // 参与拼团
  gopay(){
    let getPa = this.data.pageInfo.product;
    wx.navigateTo({
      url: "/pages/pay-order/pay-order?orderType=buyPT&order=" + this.data.order + "&id=" + getPa.id + "&groupid=" + this.data.groupid + "&buy_type=1&product_info=" + JSON.stringify([{ product_id: getPa.product_id, qty: 1 }]) 
    })
  },
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    // 带上这个数据
    if(options.getBdmin_user_id){
      util.clearLogin(options.getBdmin_user_id);
    }
    // 分享进来的
    if(options.share){
      util.stat(app,'pages/share/share',2)
    }else{
      util.stat(app,'pages/share/share',1)
    }
    var lang = wx.T.getLanguage()
    this.setData({
      order:options.order,
      id: options.id,
      groupid: options.groupid,
      product_info: options.product_info,
      language: lang,
      selectSize: lang.select_attribute
    });
    wx.setStorage({
      key: 'groupid',
      data: options.groupid,
    })
    wx.setStorage({
      key: 'productid',
      data: options.id,
    })
    wx.setStorage({
      key: 'product_info',
      data: options.product_info,
    })

    this.getInit()
  },
  // 获取初始化数据
  getInit(){
    var that=this;
    wx.request({
      url: app.globalData.urls + '/product/group-detail',
      data: {
        group_id: this.data.groupid
      },
      header: app.getRequestHeader(),
      success: (res) => {
        
        if(res.data.code==200){
          var data = res.data.data;
          that.setData({
            pageInfo:data
          })
          console.log("数据", data);
        }
      }
    })
  },
})